<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /* 利用循环进行复制数组或者对象（也可以叫做浅拷贝） */
        // var arr=[1,2,3,4];
        // var arrcopy=[];
        // for(var i=0;i<arr.length;i++){
        //     arrcopy.push(arr[i]);
        // }
        // console.log(arrcopy);
        // arrcopy[1]=6;
        // console.log(arrcopy);
        // console.log(arr);
        // for( var key in arr){
        //     arrcopy[key]=arr[key];
        // }
        // arrcopy[1]=6;
        // console.log(arrcopy);
        // console.log(arr);
        var obj={
            name:"张三",
            age:20,
            gender:"男"
        }
        var objcopy={};
        for(var key in obj){
            objcopy[key]=obj[key];
        }
        console.log(obj);
        objcopy.name="李四";
        console.log(objcopy);
    </script>
</body>
</html>